<extend name="./Application/Common/View/block/base.php" />
<block name="header">
    <include file="./Application/Admin/View/block/easyui_header.php" />
    <link rel="stylesheet" type="text/css" href="/Public/uploadfy/uploadify.css" />
    <script type="text/javascript" src="/Public/uploadfy/jquery.uploadify.min.js"></script>
    <style>
        #dg{
            height: 100%;;
        }
    </style>
</block>
<block name="bdoy">
    <body>
    <script type="text/javascript">
        //$.noConflict();
        $(window).resize(function() {
            $('#grid_gate_log').datagrid('resize');
        });

        function cleargatelogForm(){
            $('#gatelogForm').form('clear');
        }

        function clearQueryParamZone(){
            $('#queryForm_Gatelog').form('clear');
        }

        $(function(){
            $('#ps_id_combox_2').combobox({
                url:'/Manage/AdminGate/get_all_combox',
                valueField:'id',
                textField:'name',
            });
            $('#ps_id_combox_3').combobox({
                url:'/Manage/AdminGate/get_all_combox',
                valueField:'id',
                textField:'name',
            });
            $('#grid_gate_log').datagrid({
                //title:'闸门',
                width: '100%',
                //height: 400,
                fit: true,
                nowrap: false,
                striped: true,
                collapsible:false,
                url:'__URL__/log_get_all',
                queryParams:{page:1,rows:20},
                method:'get',
                pageNumber:1,
                pageSize:20,
                idField:'id',
                remoteSort: false,
                columns:[[
                    {field:'id',title:'序号',width:60,checkbox:true},
                    {field:'sta_name',title:'闸门名称',width:180,align:'center'},
                    {field:'status',title:'设备状态',width:100,align:'center'},
                    {field:'work_time',title:'开闸时长(小时)', width:100,align:'center'},
                    {field:'gate_start',title:'开闸时间',width:140,align:'center'},
                    {field:'gate_off',title:'关闸时间',width:140,align:'center'},
                    {field:'gate_reson',title:'开闸原因',width:140,align:'center'},
                    {field:'gate_height',title:'闸门开启高度',width:140,align:'center'},

                ]],
                pagination:true,
                rownumbers:true,
                singleSelect:false,
                toolbar: '#grid_gate_log_ToolBar',
                onDblClickRow: function(rowIndex, rowData) {
                    var selected = $('#grid_gate_log').datagrid('getSelected');
                    if($('#single').is(":hidden")){
                        editGatelog(rowData.id);
                    }else{
                        var rows = $('#grid_gate_log').datagrid('getSelections');
                        if(selected){
                            if(selected.id == rowData.id){
                                editGatelog(rowData.id);
                            }else{
                                $.messager.alert('提示','当前选择了多条信息，不可以编辑！','error');
                            }
                        }else{
                            editGatelog(rowData.id);
                        }
                    }
                },
                rowStyler: function(index,row){
                    if (row.status_index < 0){
                        return 'background:rgba(255, 133, 133, 1);;color:#ffffff;';
                    }
                },
                onLoadSuccess: function(data) {
                    $(this).datagrid('resize');
                    $('.gate_select').combobox('reload','/Manage/AdminGate/get_all_gate');
                }
            });

            $('#btnAddGatelog').click(function() {
                cleargatelogForm();
                $("#saveflag_gate_log").val("add");
                $('#ps_id_combox_3').combobox({
                    url:'/Manage/AdminGate/get_all_combox',
                    valueField:'id',
                    textField:'name',
                });
                $('#gatelogDlg').dialog({title:'录入闸门运行记录信息',modal:true});
                $('#gatelogDlg').dialog("open");
            });
            $('#btneditGateloglog').click(function() {
                var selected = $('#grid_gate_log').datagrid('getSelected');
                if($('#single').is(":hidden")){
                    if (selected) {
                        editGatelog(selected.id);
                    }
                }else{
                    var rows = $('#grid_gate_log').datagrid('getSelections');
                    if(rows.length == 1 || rows.length == 0){
                        if (selected) {
                            editGatelog(selected.id);
                        }
                        else{
                            $.messager.show({title: "提示",msg: "请选中一条信息，再进行编辑!"});
                        }
                    }else{
                        $.messager.alert('提示','当前选择了多条信息，不可以编辑！','error');
                        singleToggle();
                    }
                }
            });
            $('#btnDelGatelog').click(function() {

                var ids = [];
                var rows = $('#grid_gate_log').datagrid('getSelections');
                for ( var i = 0; i < rows.length; i++) {
                    ids.push(rows[i].id);
                }
                if ((ids != null) && (ids.length > 0)) {
                    $.messager.confirm('请确认', '你确定要删除吗？', function(r) {
                        if (r) {
                            $('#batchDelFormGatelog').ajaxSubmit({
                                url:"/Manage/AdminGate/log_deleteArray",
                                data:{'ids':ids.join(',')},
                                dataType:'json',
                                success: function(data) {
                                    if (data.status==1) {
                                        $('#grid_gate_log').datagrid('reload');
                                        $('#grid_gate_log').datagrid("unselectAll");
                                        $.messager.show({title:'提示',msg:'删除成功！',showType:'slide'});
                                    }
                                    else $.messager.alert('提示','删除失败！','error');
                                }
                            });

                        }
                    });
                }
            });
            $('#btnSearchGatelog').click(function() {
                $('#queryParamZone_gate_log').toggle();
                if($('#queryParamZone_gate_log').is(":hidden")){
                    clearQueryParamZone();
                }
                $('#grid_gate_log').datagrid("resize");
            });

            $('#btnQueryGatelog').click(function() {
                var obj = $('#queryForm_Gatelog').serializeJson();
                $('#grid_gate_log').datagrid('load',obj);
            });

            $('#queryParamZone_gate_log').hide();
            $('#single').hide();
        });

        function editGatelog(id) {
            if(id!=""){
                $("#saveflag_gate_log").val("update");
            }else{
                cleargatelogForm();
                $("#saveflag_gate_log").val("add");
                return;
            }
            $.ajax({url:"/Manage/AdminGate/get_obj_log_json",data:{id:id},dataType:"json",success:function(json, textStatus){
                $('#gatelogForm').form('load',{
                    "id": json.id,
                    'gateid':json.gateid,
                    "date": json.date,
                    "gate_start": json.gate_start,
                    "gate_startwaterline": json.gate_startwaterline,
                    "gate_off": json.gate_off,
                    "gate_offwaterline": json.gate_offwaterline,
                    "gate_reson": json.gate_reson,
                    "gate_height": json.gate_height,
                    "weather": json.weather,
                    "status": json.status,
                });
                $('#gatelogDlg').dialog({title:'编辑闸门信息',modal:true});
                $('#gatelogDlg').dialog("open");
                setFormFocus('#gatelogForm');
            },error:function(XMLHttpRequest, textStatus, errorThrown) {
                relogin(XMLHttpRequest, textStatus, errorThrown);
            }});
        }

        function submitgatelogForm() {
            if ($('#gatelogForm').form('validate')) {
                var submitflag = $("#saveflag_gate_log").val();
                var url = "";
                if (submitflag === "add")
                    url = "/Manage/AdminGate/log_add";
                if (submitflag === "update")
                    url = "/Manage/AdminGate/log_edit";
                $('#gatelogForm').ajaxSubmit({
                    url:url,
                    dataType:'json',
                    success: function(data) {
                        if (data.status==1) {
                            if (submitflag === "add") $('#grid_gate_log').datagrid('load');
                            if (submitflag === "update") $('#grid_gate_log').datagrid('reload');
                            $('#gatelogDlg').dialog("close");
                            $.messager.show({title:'提示',msg:'保存成功！',showType:'slide'});
                        }
                        else $.messager.alert('提示','操作失败！','error');
                    }
                });
            }else{
                console.log('no valdate');
            }
        }
    </script>
    <table id="grid_gate_log"></table>
    <div id="grid_gate_log_ToolBar" style="padding:5px;height:auto">
        <div style="margin-bottom:5px">
            <a id="btnAddGatelog" href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true">增加</a>
            <a id="btneditGateloglog" href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true">编辑</a>
            <a id="btnDelGatelog" href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
            <a id="btnSearchGatelog" href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a>
            <a id="btnReload" href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="$('#grid_gate_log').datagrid({url:'__URL__/log_get_all',queryParams:{page:1,rows:20}})">重载</a>
        </div>
        <div id="queryParamZone_gate_log">
            <form id="queryForm_Gatelog" method="post" action="">
                <table>
                    <tr>
                        <td>河闸：</td>
                        <td><input id="ps_id_combox_2" name="gateid"></td>
                        <td>设备状态：</td>
                        <td>
                            <select  name="status" style="width: 80px;">
                                {:gate_status_option()}
                            </select>
                        </td>
                        <td>从：</td>
                        <td><input class="easyui-datebox" name="start" style="width: 100px;"></td>
                        <td>到：</td>
                        <td><input class="easyui-datebox" name="end" style="width: 100px;"></td>
                        <td><a id="btnQueryGatelog" href="#" class="easyui-linkbutton" iconCls="icon-search">查询</a></td>
                        <td><a href="#" class="easyui-linkbutton" iconCls="icon-undo" onclick="javascript:$('#queryForm_Gatelog').form('clear');">重置</a></td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
    <div id="gatelogDlg" class="easyui-dialog" title="" style="width:650px;height:300px;padding:10px" buttons="#dlg-buttons-machein-log" closed="true" resizable="true">
        <form id="gatelogForm" method="post" action="">
            <input id="saveflag_gate_log" name="saveflag_gate_log" type="hidden" value="add"/>
            <input type="hidden" name="id" />
            <table border="0">
                <tr>
                    <td align="right">河闸</td>
                    <td><input id="ps_id_combox_3" required="true" name="gateid" style="width: 140px;"></td>
                </tr>
                <tr>
                    <td align="right">操作日期：</td>
                    <td>
                        <input class="easyui-datetimebox" type="text" name="date" required data-options="validType:'md[\'10/11/2012 2:33:22\']'"></input>
                    </td>
                    <td align="right">设备状态：</td>
                    <td>
                        <select class="easyui-combobox" name="status" data-options="prompt:'{:LANG('pls_input')}',required:true" style="width: 140px;">
                            {:gate_status_option()}
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right">开机时间：</td>
                    <td>
                        <input class="easyui-datetimebox" type="text" name="gate_start" ></input>
                    </td>
                    <td align="right">关机时间：</td>
                    <td>
                        <input class="easyui-datetimebox" type="text" name="gate_off" ></input>
                    </td>
                </tr>

                <tr>
                    <td align="right">开闸原因 ：</td>
                    <td>
                        <input class="easyui-textbox" type="text" name="gate_reson" style="width: 140px;"></input>
                    </td>
                    <td align="right">闸门开启高度：</td>
                    <td>
                        <input class="eeasyui-numberbox" name="gate_height" style="width: 140px;"></input>
                    </td>
                </tr>
                <tr>
                    <td align="right">天气 ：</td>
                    <td>
                        <select class="easyui-combobox" name="weather" data-options="prompt:'{:LANG('pls_input')}',required:true" style="width: 140px;">
                            {:weather_status_option()}
                        </select>
                    </td>
                </tr>

            </table>
        </form>
    </div>
    <div id="dlg-buttons-machein-log" style="text-align: center;">
        <a href="#" class="easyui-linkbutton" iconCls="icon-save" onclick="javascript:submitgatelogForm();">保存</a>
    </div>
    <form id="batchDelFormGatelog" method="post">
    </form>

    </body>
</block>
<block name="footExtendJs">

</block>